<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href="/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <script src="/jquery/jquery2.1.4.js"></script>
    <script src="/layer/layer.js"></script>
    <script src="/bootstrap/js/bootstrap.min.js"></script>
    <link href="/css/index.css" rel="stylesheet">
</head>

<body style="background-color: #ecf0f5;">
<div class="dingbu">
    <div class="denglu-font top">
        <a href="#" id="dingbuhome"><img src="/images/logo.jpg"></a>


        <div class="denglu-font2 top">
            <a href="#" id="uname">admin</a>
            <a href="/" id="login_logout">退出</a>

        </div>
    </div>
</div>
<div class="list-1">
    <ul class="list-ul-2" style="position: relative;right: 190px;">
        <div class="img"><img src="/images/logo1.jpg" width="55px" height="55px" class="img-logo"/></div>

        <li>
            <a href="/api/admin/userList" class="index_click">管理用户</a>
        </li>

        <li>
            <a href="/api/admin/itemList" class="index_click">审核商品</a>
        </li>
    </ul>
</div>
<div class="container-fluid">
    <div class="row" style="margin-top: 70px">
        <!--左边部分 -->
        <div class="col-md-10 col-md-offset-1" style="top: -20px;">
            <div class="row tzgl admin-h1" style="display: block;">
                <h1><span class="text-primary" id="article_total">商品审核</span></h1>
                <div class="col-md-12" style="background-color: #fff; border-top: 3px solid #00a65a; top: 8px;">
                    <table class="table">
                        <thead>
                        <tr>
                            <th>发布人</th>
                            <th>商品图片</th>
                            <th>商品名称</th>
                            <th>商品描述</th>
                            <th>更新时间</th>
                            <th>当前状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <!-- 用户列表 - 模板 -->
                        <tbody id="listArticle_hide">
                        <tr th:each="item:${itemList}" th:object="${item}">
                            <!-- 发布人 -->
                            <td id="articleNum">
                                <div style="width:70px;word-wrap:break-word;" th:text="*{user.username}">张一隆</div>
                            </td>
                            <!-- 商品图片 -->
                            <td id="articleTitles">
                                <div style="width:100px;word-wrap:break-word;">
                                    <img th:src="*{image}" style="width:80px;" class="mid" onclick="fun(this)">
                                </div>
                            </td>
                            <!-- 商品名称 -->
                            <td id="articleUsername" th:text="*{itemName}" style="word-wrap:break-word;">简约时尚水泥花瓶4</td>
                            <!-- 商品描述 -->
                            <td id="articleCreateTime" th:text="*{description}"
                                style="word-wrap:break-word; width: 300px">
                                这是一款很好吃的酸辣粉
                            </td>
                            <!-- 更新时间 -->
                            <td id="articleUpdateTime" th:text="*{updateTime}" style="word-wrap:break-word;">九成新</td>
                            <!-- 当前状态 -->
                            <td id="status">
                                <button type="button" disabled="disabled" th:id="'status'+*{id}" th:if="*{status==1}"
                                        class="btn btn-info btn-sm">已通过
                                </button>
                                <button type="button" disabled="disabled" th:id="'status'+*{id}" th:if="*{status==0}"
                                        class="btn btn-warning btn-sm">待审核
                                </button>
                                <button type="button" disabled="disabled" th:id="'status'+*{id}" th:if="*{status==-1}"
                                        class="btn btn-danger btn-sm">未通过
                                </button>

                            </td>
                            <!-- 操作 -->
                            <td id="listArticle_caozuo">

                                <!-- 通过 -->
                                <form method="post" th:if="*{status==1}">
                                    <div th:id="*{id}" class="div">
                                        <input th:id="'pass'+*{id}" type="button" class="btn btn-info btn-sm check"
                                               value="通过" style="display: none"/>
                                        <input th:id="'reject'+*{id}" type="button" class="btn btn-danger btn-sm reject"
                                               value="拒绝"/>
                                    </div>
                                </form>
                                <!-- 拒绝 -->
                                <form method="post" th:if="*{status==-1}">
                                    <div th:id="*{id}" class="div">
                                        <input th:id="'pass'+*{id}" type="button" class="btn btn-info btn-sm check"
                                               value="通过"/>
                                        <input th:id="'reject'+*{id}" type="button" class="btn btn-danger btn-sm reject"
                                               value="拒绝" style="display: none"/>
                                    </div>
                                </form>
                                <form method="post" th:if="*{status==0}">
                                    <div th:id="*{id}" class="div">
                                        <input th:id="'pass'+*{id}" type="button" class="btn btn-info btn-sm check"
                                               value="通过"/>
                                        <input th:id="'reject'+*{id}" type="button" class="btn btn-danger btn-sm reject"
                                               value="拒绝"/>
                                    </div>
                                </form>
                            </td>
                        </tr>

                        </tbody>
                    </table>
                </div>
            </div>
            <div class="pages" id="wants_pages" style="position: relative;top: 20px;height: 50px">
                <a href="/api/root/itemList?pageNo=1" >首页</a>

                <a th:href="'/api/admin/itemList?pageNo='+ (${itemList.hasPrevious()}?${itemList.getNumber()} : 1)">上一页</a>

                <a th:href="'/api/admin/itemList?pageNo='+ (${itemList.hasNext()}?(${itemList.getNumber()}+2):${itemList.totalPages})">下一页</a>

                <a th:href="'/api/admin/itemList?pageNo='+ ${itemList.totalPages}">尾页</a>

                当前页：<span th:text="${itemList.getNumber()}+1">1</span>

                总页数:<span th:text="${itemList.totalPages}">1</span>

                总条数:<span th:text="${itemList.totalElements}">1</span>
            </div>
        </div>
    </div>
</div>
</body>
<script>
  $(function () {
    load_data()
  })
  $('#login_logout').click(function () {
      localStorage.clear()
  })
  function load_data() {
    var theme = localStorage.getItem('username')
    console.log(localStorage.getItem('username'))
    console.log(localStorage.getItem('userId'))
    if (theme == null || theme == '') {
      $('#login_logout').text('登录')
      $('#uname').text('')
    } else {
      $('#login_logout').text('退出')
      $('#login_logout').attr('href', '/logout')
      $('#uname').text(theme)
    }
  }
    $(function () {
        $('.check').click(function () {
            var adminId = localStorage.getItem('userId')
            var itemId = $(this).parent().attr('id')
            console.log(itemId)
            $.ajax({
                type: 'POST',
                url: '/api/admin/checkItem?adminId=' + adminId + '&itemId=' + itemId + '&status=1',
                contentType: 'application/json',
                traditional: true,
                success: function (data) {
                    layer.msg(data.msg)
                    if (data.code == 0) {
                        $('#pass' + itemId).hide()
                        $('#reject' + itemId).attr("style", "display:block")
                        $('#status' + itemId).attr('class', 'btn btn-info btn-sm')
                        $('#status' + itemId).text('已通过')
                    }
                },
                error: function (data) {
                }
            })
        })

        $('.reject').click(function () {
            var adminId = localStorage.getItem('userId')

            var itemId = $(this).parent().attr('id')
            console.log(itemId)
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/api/admin/checkItem?adminId=' + adminId + '&itemId=' + itemId + '&status=-1',
                contentType: 'application/json',
                traditional: true,
                success: function (data) {
                    layer.msg(data.msg)
                    if (data.code == 0) {
                        $('#pass' + itemId).attr("style", "display:block")
                        $('#reject' + itemId).hide()
                        $('#status' + itemId).attr('class', 'btn btn-danger btn-sm')
                        $('#status' + itemId).text('未通过')
                    }
                },
                error: function (data) {
                }
            })
        })

    })

</script>

</html>